﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class HoaDonMuaHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // fill constituent controls with data
        PopulateControls();
    }

    // populate the form with data
    private void PopulateControls()
    {
        // obtain order ID from the session
        int orderId = int.Parse(Request.QueryString["id"]);
        // obtain order info
        DonDatHangBUS OrdersAccess =
            new DonDatHangBUS(TGDDConfiguration.DbConnectionString);
        DataSet objDataSet = OrdersAccess.GetInfoDonDatHang(orderId);
        DataRow row = objDataSet.Tables[0].Rows[0];
        DonDatHangDTO orderInfo = new DonDatHangDTO();
        orderInfo.Id = int.Parse(row["id"].ToString());
        orderInfo.ThanhTien = long.Parse(row["ThanhTien"].ToString());
        orderInfo.NgayDatHang = DateTime.Parse(row["NgayDatHang"].ToString());
        orderInfo.XacNhan = bool.Parse(row["XacNhan"].ToString());
        orderInfo.DaGiao = bool.Parse(row["DaGiao"].ToString());
        orderInfo.GhiChu = row["GhiChu"].ToString();
        orderInfo.TenKhachHang = row["TenKhachHang"].ToString();
        orderInfo.DiaChiNguoiNhan = row["DiaChiNguoiNhan"].ToString();

        txtTenNguoiNhan.Text = row["TenNguoiNhan"].ToString();
        txtSDTNguoiNhan.Text = row["SDTNguoiNhan"].ToString();
        txtDiaChiNguoiNhan.Text = row["DiaChiNguoiNhan"].ToString();

        // populate labels and text boxes with order info
        orderIdLabel.Text = "Hóa đơn mua hàng";
        totalAmountLabel.Text = String.Format("{0:#,##0;Nothing}", orderInfo.ThanhTien);
        dateCreatedTextBox.Text = orderInfo.NgayDatHang.ToString();

        customerNameTextBox.Text = orderInfo.TenKhachHang;

        // fill the data grid with order details
        objDataSet = OrdersAccess.GetDetailsDonDatHang(orderId);
        grid.DataSource = objDataSet.Tables[0];
        grid.DataBind();
    }
}